package ch.uzh.ifi.sonar.shells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class SonarDashboard {

	private TabFolder tabFolder;
	private Tab[] tabs;

	public SonarDashboard(Composite parent) {
		tabFolder = new TabFolder(parent, SWT.NONE);
		tabs = createTabs();
		for (int i = 0; i < tabs.length; i++) {
			TabItem item = new TabItem(tabFolder, SWT.NONE);
			item.setText(tabs[i].getTabText());
			item.setControl(tabs[i].createTabFolderPage(tabFolder));
			item.setData(tabs[i]);
		}
	}

	public void setFocus() {

	}

	public void dispose() {

	}

	Tab[] createTabs() {
		return new Tab[] { new QueryTab(this), new BrowserTab(this) };
	}

	/**
	 * Sets the size of the shell to it's "packed" size, unless that makes it
	 * larger than the monitor it is being displayed on, in which case just set
	 * the shell size to be slightly smaller than the monitor.
	 */
	static void setShellSize(SonarDashboard instance, Shell shell) {
		Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		Rectangle monitorArea = shell.getMonitor().getClientArea();
		shell.setSize(Math.min(size.x, monitorArea.width),
				Math.min(size.y, monitorArea.height));
	}
}
